package main

import (
	"fmt"
	"strconv"
	"strings"
)

//strings 工具
func main() {
	//Contains
	fmt.Println(strings.Contains("hello world", "xxx"))
	//Join
	s := []string{"abc", "hello", "tom"}
	fmt.Println(strings.Join(s, "@"))
	//Index 不存在返回-1
	fmt.Println(strings.Index("abcdhello", "hello"))
	//Repeat
	fmt.Println(strings.Repeat("go", 3))
	//Replace
	//Split
	a := "abc@hello@tom"
	fmt.Println(strings.Split(a, "@"))
	//Trim
	b := "    are you ok    "
	fmt.Println(strings.Trim(b, " "))
	//Fields
	fmt.Println(strings.Fields(b))
	//字符串转换
	//string到int
	i1, err := strconv.Atoi("123")
	if err == nil {
		fmt.Println("i1=", i1)
	} else {
		fmt.Println(err)
	}
	//string到int64
	i2, err := strconv.ParseInt("1234567891011121314", 10, 64)
	if err == nil {
		fmt.Println("i2=", i2)
	} else {
		fmt.Println(err)
	}
	//int到string
	scv0 := strconv.Itoa(i1)
	fmt.Println("scv0=", scv0)
	//int64到string
	scv1 := strconv.FormatInt(i2, 10)
	fmt.Println("scv1=", scv1)
}
